home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / DEMONSTR / ATEASY_2.ZIP / DLLEXAMP.C < prev    next >
C/C++ Source or Header  |  1992-07-29  |  5KB  |  144 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: DLLEXAMP.c
  4.  
  5.     PURPOSE: Demonstarte ATEasy DLL functions
  6.              using MSC 5.1+/QC-Win/Borland C++
  7.  
  8.     VERSION: 1.10 (Dec-12-91)
  9.  
  10.     FUNCTIONS:
  11.  
  12.          - Max() : finds the max between 2 floats
  13.          - AverageArray() : find the avarage of float array
  14.          - NoSpaces() : delete leading & trailing spaces in a string
  15.  
  16. ****************************************************************************/
  17.  
  18. #include "windows.h"
  19. #include "ateasydl.h"   /* contains ATEasy VAL, VAR parameters definitions */
  20. #include "string.h"     /* for memmove */
  21. #include "ctype.h"      /* for isspace */
  22.  
  23. /****************************************************************************
  24.    FUNCTION: LibMain(HANDLE, WORD, WORD, LPSTR)
  25.  
  26.    PURPOSE:  Is called by LibEntry.  LibEntry is called by Windows when
  27.              the DLL is loaded.  The LibEntry routine is provided in
  28.              the LIBENTRY.OBJ in the SDK Link Libraries disk.  (The
  29.              source LIBENTRY.ASM is also provided.)
  30.  
  31.              LibEntry initializes the DLL's heap, if a HEAPSIZE value is
  32.              specified in the DLL's DEF file.  Then LibEntry calls
  33.              LibMain.  The LibMain function below satisfies that call.
  34.  
  35.              The LibMain function should perform additional initialization
  36.              tasks required by the DLL.  In this example, no initialization
  37.              tasks are required.  LibMain should return a value of 1 if
  38.              the initialization is successful.
  39.  
  40. ****************************************************************************/
  41. int FAR PASCAL LibMain(hModule, wDataSeg, cbHeapSize, lpszCmdLine)
  42. HANDLE  hModule;
  43. WORD    wDataSeg;
  44. WORD    cbHeapSize;
  45. LPSTR   lpszCmdLine;
  46. {
  47.     return(1);
  48. }
  49.  
  50.  
  51. /****************************************************************************
  52.  
  53.     FUNCTION: WEP(int)
  54.  
  55.     PURPOSE:  Performs cleanup tasks when the DLL is unloaded.  WEP() is
  56.               called automatically by Windows when the DLL is unloaded (no
  57.               remaining tasks still have the DLL loaded).  It is strongly
  58.               recommended that a DLL have a WEP() function, even if it does
  59.               nothing but returns success (1), as in this example.
  60.  
  61. ****************************************************************************/
  62. int FAR PASCAL WEP(bSystemExit)
  63. int  bSystemExit;
  64. {
  65.     return(1);
  66. }
  67.  
  68.  
  69. /****************************************************************************
  70.  
  71.     FUNCTION: Max(hWnd, dX1, dX2, lpdResult)
  72.  
  73.     PURPOSE:  Finds the max of 2 floats (dX1 & dX2) into lpdResult.
  74.  
  75.        This function defined in ATEasy as:
  76.        Max(X1 : VAL FLOAT, X2 : VAL FLOAT, Result : VAR FLOAT) : SUB DLL
  77.  
  78. ****************************************************************************/
  79. VOID FAR PASCAL Max(hWnd, dX1, dX2, lpdResult)
  80. HWND            hWnd;
  81. VAL_FLOAT       dX1, dX2;
  82. VAR_FLOAT       lpdResult;
  83. {
  84.     *lpdResult=dX1 > dX2 ? dX1 : dX2;
  85. }
  86.  
  87.  
  88. /****************************************************************************
  89.  
  90.     FUNCTION: AverageArray(hWnd, FloatArray, lpdResult)
  91.  
  92.     PURPOSE:  Finds the avarage of FloatArray into lpdResult.
  93.  
  94.         This function defined in ATEasy as:
  95.         AverageArray(Array : VAL FLOAT[], Result : VAR FLOAT) : SUB DLL
  96.  
  97. ****************************************************************************/
  98. VOID FAR PASCAL AverageArray(hWnd, FloatArray, lpdResult)
  99. HWND            hWnd;
  100. VAL_AFLOAT      FloatArray;
  101. VAR_FLOAT       lpdResult;
  102. {
  103.     double      ldResult=0.0;
  104.     short       i;
  105.  
  106.     for (i=0; i < FloatArray->nDim2; i++)
  107.         ldResult+=(FloatArray->Ptr.lpFloat)[i];
  108.     if (FloatArray->nDim2)
  109.         ldResult/=FloatArray->nDim2;
  110.     *lpdResult=ldResult;
  111. }
  112.  
  113.  
  114. /****************************************************************************
  115.  
  116.     FUNCTION: NoSpaces(hWnd, String)
  117.  
  118.     PURPOSE:  Delete leading & trailing spaces in a string
  119.  
  120.         This function defined in ATEasy as:
  121.         NoSpaces(Str : VAR String)
  122.  
  123. ****************************************************************************/
  124. VOID FAR PASCAL NoSpaces(hWnd, String)
  125. HWND            hWnd;
  126. VAR_ASTRING     String;
  127. {
  128.     short       i, j;
  129.  
  130.     for (i=StrLen(String); i > 0; i--)         /* delete trailing spaces */
  131.         if (!isspace(Str(String)[i-1])) break;
  132.     StrLen(String)=i;
  133.     for (j=0; j < i; j++)                      /* delete leading spaces */
  134.         if (!isspace(Str(String)[j])) break;
  135.     if (j)                                     /* move to start */
  136.     {   StrLen(String)-=j;
  137.         memmove(Str(String), &Str(String)[j], StrLen(String));
  138.     }
  139. }
  140.  
  141. /****************************************************************************
  142.                     E - O - F
  143. ****************************************************************************/
  144.